package doantotnghiep.daoimpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;

import doantotnghiep.dao.DivisionRoomDao;
import doantotnghiep.model.DivisionRoom;

public class DivisionRoomDaoImpl implements DivisionRoomDao {
	
	@Autowired
	private HibernateTemplate hibernateTemplate;

	@Override
	public void addRoom(DivisionRoom divisionRoom) {
		this.hibernateTemplate.saveOrUpdate(divisionRoom);	
	}

	@SuppressWarnings("unchecked")
	@Override
	public DivisionRoom getRoomByID(int id) {	
		List<DivisionRoom> rooms = hibernateTemplate.find("from DivisionRoom where status = 0 and id ="+ id);
		if(rooms!=null){
			return rooms.get(0);
		}
		return null;
	}

	@Override
	public void deleteRoom(int id) {
		DivisionRoom entity = this.getRoomByID(id);
		if (entity != null){
			entity.setStatus(1);
			this.hibernateTemplate.saveOrUpdate(entity);
		}
	}

	@Override
	public void saveRoom(DivisionRoom divisionRoom) {
		this.hibernateTemplate.saveOrUpdate(divisionRoom);			
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<DivisionRoom> getListRoom() {
		return hibernateTemplate.find("from DivisionRoom where status = 0 ");
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<DivisionRoom> getListValidRoom() {
		return hibernateTemplate.find("from DivisionRoom where status = 0 and id > 1 ");
	}
	

}
